﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace BizElements.TemplateEngine
{
    /// <summary>Template setting (name, value, description).</summary>
    public sealed class TemplateSetting
    {
        #region Properties.

        /// <summary>Gets setting name.</summary>
        public string Name { get; internal set; }

        /// <summary>Gets setting description.</summary>
        public string Description { get; internal set; }

        /// <summary>Gets setting value.</summary>
        public string Value { get; internal set; }

        #endregion
    }

    /// <summary>Represents a read-only collection of key/value pairs where the key represents setting name and the value represents TemplateSetting object.</summary>
    public sealed class TemplateSettingCollection : IEnumerable<KeyValuePair<string, TemplateSetting>>
    {
        #region CTor.

        /// <summary>Initializes a new instance of <b>TemplateSettingCollection</b> class.</summary>
        public TemplateSettingCollection(IDictionary<string, TemplateSetting> variables)
        {
            this.variables = variables;
        }

        #endregion

        #region Indexer.

        IDictionary<string, TemplateSetting> variables;

        /// <summary>Gets setting with the specified name.</summary>
        public string this[string name]
        {
            get
            {
                TemplateSetting var;
                bool exists = this.variables.TryGetValue(name, out var);
                return (exists) ? var.Value : "";
            }
        }

        #endregion

        #region IEnumerable<KeyValuePair<string,TemplateSetting>> Members

        /// <summary>Returns an enumerator that iterates through the collection.</summary>
        /// <returns>An IEnumerator object that can be used to iterate through the collection.</returns>
        public IEnumerator<KeyValuePair<string, TemplateSetting>> GetEnumerator()
        {
            return this.variables.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        /// <summary>Returns an enumerator that iterates through the collection.</summary>
        /// <returns>An IEnumerator object that can be used to iterate through the collection.</returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.variables.GetEnumerator();
        }

        #endregion
    }
}